
<!DOCTYPE HTML>
<html lang="zh-hans" >
    <head>
        <meta charset="UTF-8">
        <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
        <title>kotlin基础 · Aivin开发笔记</title>
        <meta http-equiv="X-UA-Compatible" content="IE=edge" />
        <meta name="description" content="">
        <meta name="generator" content="GitBook 3.2.3">
        <meta name="author" content="Aivin">
        
        
    
    <link rel="stylesheet" href="../gitbook/style.css">

    
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-search-plus/search.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-anchor-navigation-ex/style/plugin.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-fontsettings/website.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-tbfed-pagefooter/footer.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-donate/plugin.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-local-video/video-js.min.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-splitter/splitter.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-highlight/website.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-theme-comscore/test.css">
                
            
        

    

    
        
        <link rel="stylesheet" href="../styles/website.css">
        
    

        
    
    
    
    <meta name="HandheldFriendly" content="true"/>
    <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <link rel="apple-touch-icon-precomposed" sizes="152x152" href="../gitbook/images/apple-touch-icon-precomposed-152.png">
    <link rel="shortcut icon" href="../gitbook/images/favicon.ico" type="image/x-icon">

    
    
    <link rel="prev" href="../" />
    

    
        <link rel="shortcut icon" href='../assets/images/favicon.ico' type="image/x-icon">
    
    
        <link rel="bookmark" href='../assets/images/favicon.ico' type="image/x-icon">
    
    
    

    </head>
    <body>
        
<div class="book">
    <div class="book-summary">
        
            
<div id="book-search-input" role="search">
    <input type="text" placeholder="输入并搜索" />
</div>

            
                <nav role="navigation">
                


<ul class="summary">
    
    

    

    
        
        
    
        <li class="chapter " data-level="1.1" data-path="../">
            
                <a href="../">
            
                    
                    个人信息
            
                </a>
            

            
        </li>
    
        <li class="chapter active" data-level="1.2" data-path="kotlin基础.html">
            
                <a href="kotlin基础.html">
            
                    
                    kotlin基础
            
                </a>
            

            
        </li>
    

    

    <li class="divider"></li>

    <li>
        <a href="https://www.gitbook.com" target="blank" class="gitbook-link">
            本书使用 GitBook 发布
        </a>
    </li>
</ul>


                </nav>
            
        
    </div>

    <div class="book-body">
        
            <div class="body-inner">
                
                    

<div class="book-header" role="navigation">
    

    <!-- Title -->
    <h1>
        <i class="fa fa-circle-o-notch fa-spin"></i>
        <a href=".." >kotlin基础</a>
    </h1>
</div>




                    <div class="page-wrapper" tabindex="-1" role="main">
                        <div class="page-inner">
                            
<div class="search-plus" id="book-search-results">
    <div class="search-noresults">
    
                                <section class="normal markdown-section">
                                
                                <div id="anchor-navigation-ex-navbar"><i class="fa fa-navicon"></i><ul><li><span class="title-icon "></span><a href="#kotlin"><b>1. </b>kotlin</a></li><ul><li><span class="title-icon "></span><a href="#&#x5B98;&#x65B9;&#x6216;&#x7B2C;&#x4E09;&#x65B9;&#x5DE5;&#x5177;"><b>1.1. </b>&#x5B98;&#x65B9;&#x6216;&#x7B2C;&#x4E09;&#x65B9;&#x5DE5;&#x5177;</a></li><li><span class="title-icon "></span><a href="#&#x8BBF;&#x95EE;&#x8303;&#x56F4;"><b>1.2. </b>&#x8BBF;&#x95EE;&#x8303;&#x56F4;</a></li><li><span class="title-icon "></span><a href="#&#x6570;&#x636E;&#x7C7B;&#x578B;"><b>1.3. </b>&#x6570;&#x636E;&#x7C7B;&#x578B;</a></li><li><span class="title-icon "></span><a href="#&#x53D8;&#x91CF;-&#x3001;&#x5E38;&#x91CF;"><b>1.4. </b>&#x53D8;&#x91CF; &#x3001;&#x5E38;&#x91CF;</a></li><li><span class="title-icon "></span><a href="#&#x51FD;&#x6570;"><b>1.5. </b>&#x51FD;&#x6570;</a></li><li><span class="title-icon "></span><a href="#&#x5B57;&#x7B26;&#x4E32;&#x6A21;&#x677F;"><b>1.6. </b>&#x5B57;&#x7B26;&#x4E32;&#x6A21;&#x677F;</a></li><li><span class="title-icon "></span><a href="#&#x96C6;&#x5408;"><b>1.7. </b>&#x96C6;&#x5408;</a></li><li><span class="title-icon "></span><a href="#&#x7A7A;&#x6307;&#x9488;"><b>1.8. </b>&#x7A7A;&#x6307;&#x9488;</a></li><li><span class="title-icon "></span><a href="#&#x6807;&#x7B7E;"><b>1.9. </b>@&#x6807;&#x7B7E;</a></li><li><span class="title-icon "></span><a href="#&#x7C7B;&#x578B;&#x8F6C;&#x6362;"><b>1.10. </b>&#x7C7B;&#x578B;&#x8F6C;&#x6362;</a></li><li><span class="title-icon "></span><a href="#&#x5BF9;&#x8C61;"><b>1.11. </b>&#x5BF9;&#x8C61;</a></li><li><span class="title-icon "></span><a href="#&#x63A5;&#x53E3;"><b>1.12. </b>&#x63A5;&#x53E3;</a></li><li><span class="title-icon "></span><a href="#&#x7C7B;&#x521D;&#x59CB;&#x5316;"><b>1.13. </b>&#x7C7B;&#x521D;&#x59CB;&#x5316;</a></li><li><span class="title-icon "></span><a href="#apply"><b>1.14. </b>apply</a></li><li><span class="title-icon "></span><a href="#with"><b>1.15. </b>with</a></li><li><span class="title-icon "></span><a href="#when"><b>1.16. </b>when</a></li><li><span class="title-icon "></span><a href="#intarrayof"><b>1.17. </b>intArrayOf</a></li><li><span class="title-icon "></span><a href="#&#x4F4D;&#x8FD0;&#x7B97;&#x7B26;"><b>1.18. </b>&#x4F4D;&#x8FD0;&#x7B97;&#x7B26;</a></li><li><span class="title-icon "></span><a href="#&#x5FAA;&#x73AF;"><b>1.19. </b>&#x5FAA;&#x73AF;</a></li><li><span class="title-icon "></span><a href="#mapto"><b>1.20. </b>mapTo</a></li><li><span class="title-icon "></span><a href="#&#x4E09;&#x76EE;&#x8868;&#x8FBE;&#x5F0F;"><b>1.21. </b>&#x4E09;&#x76EE;&#x8868;&#x8FBE;&#x5F0F;</a></li><li><span class="title-icon "></span><a href="#data"><b>1.22. </b>data</a></li><li><span class="title-icon "></span><a href="#let"><b>1.23. </b>let</a></li><li><span class="title-icon "></span><a href="#&#x53CC;&#x5192;&#x53F7;-"><b>1.24. </b>&#x53CC;&#x5192;&#x53F7; ::</a></li><ul><li><span class="title-icon "></span><a href="#&#x539F;&#x751F;&#x5B57;&#x7B26;&#x4E32;--&#x4E09;&#x5F15;&#x53F7;"><b>1.24.1. </b>&#x539F;&#x751F;&#x5B57;&#x7B26;&#x4E32;  &#x4E09;&#x5F15;&#x53F7;</a></li></ul><li><span class="title-icon "></span><a href="#&#x7EE7;&#x627F;"><b>1.25. </b>&#x7EE7;&#x627F;</a></li><li><span class="title-icon "></span><a href="#&#x51FD;&#x6570;&#x91CD;&#x5199;&#x3001;&#x5C5E;&#x6027;&#x91CD;&#x5199;"><b>1.26. </b>&#x51FD;&#x6570;&#x91CD;&#x5199;&#x3001;&#x5C5E;&#x6027;&#x91CD;&#x5199;</a></li><li><span class="title-icon "></span><a href="#&#x62D3;&#x5C55;&#x51FD;&#x6570;"><b>1.27. </b>&#x62D3;&#x5C55;&#x51FD;&#x6570;</a></li><li><span class="title-icon "></span><a href="#&#x4F34;&#x751F;&#x5BF9;&#x8C61;"><b>1.28. </b>&#x4F34;&#x751F;&#x5BF9;&#x8C61;</a></li><li><span class="title-icon "></span><a href="#&#x6570;&#x636E;&#x7C7B;"><b>1.29. </b>&#x6570;&#x636E;&#x7C7B;</a></li><li><span class="title-icon "></span><a href="#&#x5BC6;&#x5C01;&#x7C7B;"><b>1.30. </b>&#x5BC6;&#x5C01;&#x7C7B;</a></li><li><span class="title-icon "></span><a href="#&#x679A;&#x4E3E;"><b>1.31. </b>&#x679A;&#x4E3E;</a></li><li><span class="title-icon "></span><a href="#&#x6302;&#x8D77;&#x51FD;&#x6570;"><b>1.32. </b>&#x6302;&#x8D77;&#x51FD;&#x6570;</a></li><li><span class="title-icon "></span><a href="#&#x534F;&#x7A0B;"><b>1.33. </b>&#x534F;&#x7A0B;</a></li><li><span class="title-icon "></span><a href="#&#x547D;&#x540D;&#x53C2;&#x6570;-&#x3001;-&#x9ED8;&#x8BA4;&#x53C2;&#x6570;"><b>1.34. </b>&#x547D;&#x540D;&#x53C2;&#x6570; &#x3001; &#x9ED8;&#x8BA4;&#x53C2;&#x6570;</a></li><li><span class="title-icon "></span><a href="#kotlin-main-&#x5165;&#x53E3;&#x51FD;&#x6570;"><b>1.35. </b>kotlin main &#x5165;&#x53E3;&#x51FD;&#x6570;</a></li><li><span class="title-icon "></span><a href="#kotlin-&#x8C03;&#x7528;-java"><b>1.36. </b>kotlin &#x8C03;&#x7528; java</a></li><li><span class="title-icon "></span><a href="#java&#x8C03;&#x7528;kotlin&#x4EE3;&#x7801;"><b>1.37. </b>java&#x8C03;&#x7528;kotlin&#x4EE3;&#x7801;</a></li><li><span class="title-icon "></span><a href="#init"><b>1.38. </b>init</a></li><li><span class="title-icon "></span><a href="#&#x5BF9;&#x8C61;&#x8868;&#x8FBE;&#x5F0F;"><b>1.39. </b>&#x5BF9;&#x8C61;&#x8868;&#x8FBE;&#x5F0F;</a></li><li><span class="title-icon "></span><a href="#&#x76D1;&#x542C;&#x51FD;&#x6570;"><b>1.40. </b>&#x76D1;&#x542C;&#x51FD;&#x6570;</a></li><li><span class="title-icon "></span><a href="#&#x65B0;&#x5EFA;&#x5BF9;&#x8C61;"><b>1.41. </b>&#x65B0;&#x5EFA;&#x5BF9;&#x8C61;</a></li><li><span class="title-icon "></span><a href="#get-set-&#x65B9;&#x6CD5;"><b>1.42. </b>get set &#x65B9;&#x6CD5;</a></li><li><span class="title-icon "></span><a href="#&#x5EF6;&#x8FDF;&#x521D;&#x59CB;&#x5316;-&#x3001;-&#x61D2;&#x52A0;&#x8F7D;"><b>1.43. </b>&#x5EF6;&#x8FDF;&#x521D;&#x59CB;&#x5316; &#x3001; &#x61D2;&#x52A0;&#x8F7D;</a></li><li><span class="title-icon "></span><a href="#&#x7C7B;&#x578B;&#x8F6C;&#x6362;_1"><b>1.44. </b>&#x7C7B;&#x578B;&#x8F6C;&#x6362;</a></li><li><span class="title-icon "></span><a href="#&#x59D4;&#x6258;-by"><b>1.45. </b>&#x59D4;&#x6258; by</a></li><li><span class="title-icon "></span><a href="#&#x661F;&#x53F7;-"><b>1.46. </b>&#x661F;&#x53F7; *</a></li><li><span class="title-icon "></span><a href="#&#x6CDB;&#x578B;"><b>1.47. </b>&#x6CDB;&#x578B;</a></li><li><span class="title-icon "></span><a href="#kotlin-&#x8C03;&#x7528;jni"><b>1.48. </b>kotlin &#x8C03;&#x7528;jni</a></li><li><span class="title-icon "></span><a href="#return"><b>1.49. </b>return@</a></li></ul></ul></div><a href="#kotlin" id="anchorNavigationExGoTop"><i class="fa fa-arrow-up"></i></a><h1 id="kotlin"><a name="kotlin" class="anchor-navigation-ex-anchor" href="#kotlin"><i class="fa fa-link" aria-hidden="true"></i></a>1. kotlin</h1>
<p>Kotlin&#x662F;JetBrains &#x5F00;&#x53D1;&#x7684;&#x57FA;&#x4E8E;JVM&#x7684;&#x8BED;&#x8A00;&#x3002;&#x5B8C;&#x5168;&#x517C;&#x5BB9;java&#x3002;</p>
<p>kotlin&#x7EC3;&#x624B;&#x5C0F;&#x9879;&#x76EE; 
<a href="https://github.com/git-xuhao/KotlinMvp" target="_blank">https://github.com/git-xuhao/KotlinMvp</a> </p>
<pre><code class="lang-xml">DSL&#xFF08;domain specific language&#xFF09;
&#x5373;&#x9886;&#x57DF;&#x4E13;&#x7528;&#x8BED;&#x8A00;&#xFF1A;&#x4E13;&#x95E8;&#x89E3;&#x51B3;&#x67D0;&#x4E00;&#x7279;&#x5B9A;&#x95EE;&#x9898;&#x7684;&#x8BA1;&#x7B97;&#x673A;&#x8BED;&#x8A00;&#xFF0C;&#x6BD4;&#x5982;&#x5927;&#x5BB6;&#x8033;&#x719F;&#x80FD;&#x8BE6;&#x7684; SQL &#x548C;&#x6B63;&#x5219;&#x8868;&#x8FBE;&#x5F0F;&#x3002;
</code></pre>
<h2 id="&#x5B98;&#x65B9;&#x6216;&#x7B2C;&#x4E09;&#x65B9;&#x5DE5;&#x5177;"><a name="&#x5B98;&#x65B9;&#x6216;&#x7B2C;&#x4E09;&#x65B9;&#x5DE5;&#x5177;" class="anchor-navigation-ex-anchor" href="#&#x5B98;&#x65B9;&#x6216;&#x7B2C;&#x4E09;&#x65B9;&#x5DE5;&#x5177;"><i class="fa fa-link" aria-hidden="true"></i></a>1.1. &#x5B98;&#x65B9;&#x6216;&#x7B2C;&#x4E09;&#x65B9;&#x5DE5;&#x5177;</h2>
<pre><code class="lang-xml">Anko
&#x4EE5;&#x5F80;&#x7684;&#x5E03;&#x5C40;&#x90FD;&#x662F;&#x8981;&#x4ECE; XML &#x4E2D;&#x89E3;&#x6790;&#x51FA;&#x6765;&#x3002;
&#x800C; Anko &#x5219;&#x662F;&#x76F4;&#x63A5;&#x521B;&#x5EFA; View&#xFF0C;&#x7528;&#x4EE3;&#x7801;&#x6784;&#x5EFA;&#x5E03;&#x5C40;&#xFF0C;&#x7701;&#x53BB;&#x4E86;&#x89E3;&#x6790; XML &#x7684;&#x65F6;&#x95F4;&#x3002;


Kotlin Android &#x6269;&#x5C55; 
https://www.kotlincn.net/docs/tutorials/android-plugin.html
findViewById() &#x3002;&#x5C3D;&#x7BA1;&#x5B58;&#x5728;&#x4E00;&#x7CFB;&#x5217;&#x7684;&#x5F00;&#x6E90;&#x5E93;&#x80FD;&#x591F;&#x4E3A;&#x8FD9;&#x4E2A;&#x95EE;&#x9898;&#x5E26;&#x6765;&#x89E3;&#x51B3;&#x65B9;&#x6848;&#x3002;
&#x73B0;&#x5728; Kotlin &#x5B89;&#x5353;&#x6269;&#x5C55;&#x63D2;&#x4EF6;&#x80FD;&#x591F;&#x63D0;&#x4F9B;&#x4E0E;&#x8FD9;&#x4E9B;&#x5F00;&#x6E90;&#x5E93;&#x529F;&#x80FD;&#x76F8;&#x540C;&#x7684;&#x4F53;&#x9A8C;&#xFF0C;&#x4E0D;&#x9700;&#x8981;&#x6DFB;&#x52A0;&#x4EFB;&#x4F55;&#x989D;&#x5916;&#x4EE3;&#x7801;&#x3002;
apply plugin: &apos;kotlin-android-extensions&apos; //&#x6269;&#x5C55;&#x63D2;&#x4EF6;
import kotlinx.android.synthetic.main.&#xFF1C;&#x5E03;&#x5C40;&#xFF1E;.*   //&#x5173;&#x8054;xml


ktor
&#x7531; Kotlin &#x56E2;&#x961F;&#x6253;&#x9020;&#x7684; Web &#x6846;&#x67B6; &#xFF0C;&#x53EF;&#x4EE5;&#x7528;&#x6765;&#x7F16;&#x5199;&#x670D;&#x52A1;&#x5668;&#x3002;
</code></pre>
<h2 id="&#x8BBF;&#x95EE;&#x8303;&#x56F4;"><a name="&#x8BBF;&#x95EE;&#x8303;&#x56F4;" class="anchor-navigation-ex-anchor" href="#&#x8BBF;&#x95EE;&#x8303;&#x56F4;"><i class="fa fa-link" aria-hidden="true"></i></a>1.2. &#x8BBF;&#x95EE;&#x8303;&#x56F4;</h2>
<pre><code class="lang-xml">private,
protected  //&#x5B50;&#x7C7B;&#x53EF;&#x89C1;
internal // &#x540C;&#x4E00;&#x6A21;&#x5757;
public
</code></pre>
<h2 id="&#x6570;&#x636E;&#x7C7B;&#x578B;"><a name="&#x6570;&#x636E;&#x7C7B;&#x578B;" class="anchor-navigation-ex-anchor" href="#&#x6570;&#x636E;&#x7C7B;&#x578B;"><i class="fa fa-link" aria-hidden="true"></i></a>1.3. &#x6570;&#x636E;&#x7C7B;&#x578B;</h2>
<pre><code class="lang-java">Byte&#x3001;Short&#x3001;Int&#x3001;Long&#x3001;Float&#x3001;Double &#x3001;Boolean &#x3001;String
</code></pre>
<h2 id="&#x53D8;&#x91CF;-&#x3001;&#x5E38;&#x91CF;"><a name="&#x53D8;&#x91CF;-&#x3001;&#x5E38;&#x91CF;" class="anchor-navigation-ex-anchor" href="#&#x53D8;&#x91CF;-&#x3001;&#x5E38;&#x91CF;"><i class="fa fa-link" aria-hidden="true"></i></a>1.4. &#x53D8;&#x91CF; &#x3001;&#x5E38;&#x91CF;</h2>
<pre><code class="lang-java">var value : Int = <span class="hljs-number">10</span>   <span class="hljs-comment">// &#x53D8;&#x91CF;</span>
val name  : String =<span class="hljs-string">&quot;abcdedfdfa&quot;</span>   <span class="hljs-comment">// &#x5E38;&#x91CF;</span>
</code></pre>
<h2 id="&#x51FD;&#x6570;"><a name="&#x51FD;&#x6570;" class="anchor-navigation-ex-anchor" href="#&#x51FD;&#x6570;"><i class="fa fa-link" aria-hidden="true"></i></a>1.5. &#x51FD;&#x6570;</h2>
<pre><code class="lang-java"><span class="hljs-comment">// fun ,&#x6709;&#x53C2;&#x6570; &#xFF0C;&#x6709;&#x8FD4;&#x56DE;&#x503C;</span>
<span class="hljs-function">fun <span class="hljs-title">sum</span><span class="hljs-params">(a: Int, b: Int)</span>: String </span>{
    <span class="hljs-keyword">return</span> (a + b).toString()
}

<span class="hljs-comment">// &#x65E0;&#x8FD4;&#x56DE;&#x503C;</span>
<span class="hljs-function">fun <span class="hljs-title">showInfo</span><span class="hljs-params">(a: Int, b: Int)</span></span>{
}

<span class="hljs-comment">// vararg&#x662F;&#x5173;&#x952E;&#x5B57; &#x53EF;&#x53D8;&#x53C2;&#x6570; </span>
<span class="hljs-function">fun <span class="hljs-title">vars</span><span class="hljs-params">(vararg v:Int)</span></span>{
    <span class="hljs-keyword">for</span>(vt in v){
        <span class="hljs-comment">//...</span>
    }
}
</code></pre>
<h2 id="&#x5B57;&#x7B26;&#x4E32;&#x6A21;&#x677F;"><a name="&#x5B57;&#x7B26;&#x4E32;&#x6A21;&#x677F;" class="anchor-navigation-ex-anchor" href="#&#x5B57;&#x7B26;&#x4E32;&#x6A21;&#x677F;"><i class="fa fa-link" aria-hidden="true"></i></a>1.6. &#x5B57;&#x7B26;&#x4E32;&#x6A21;&#x677F;</h2>
<pre><code class="lang-java">val age  :Int = <span class="hljs-number">20</span>
var info :String =<span class="hljs-string">&quot;&#x5E74;&#x9F84;&#x662F;$age&quot;</span>
<span class="hljs-comment">//&#x590D;&#x6742;&#x683C;&#x5F0F;</span>
var info2 = <span class="hljs-string">&quot;$info &#x5B57;&#x7B26;&#x4E32;&#x957F;&#x5EA6;&#x662F;${info.length}&quot;</span>
</code></pre>
<h2 id="&#x96C6;&#x5408;"><a name="&#x96C6;&#x5408;" class="anchor-navigation-ex-anchor" href="#&#x96C6;&#x5408;"><i class="fa fa-link" aria-hidden="true"></i></a>1.7. &#x96C6;&#x5408;</h2>
<pre><code class="lang-xml">// List
val list: List<span class="hljs-tag">&lt;<span class="hljs-name">Any</span>&gt;</span> = listOf<span class="hljs-tag">&lt;<span class="hljs-name">Any</span>&gt;</span>(1, &quot;2&quot;, 3)

// Array 
val faces = Array(5) {  &quot;a&quot;   } // Array&#x521D;&#x59CB;&#x5316;&#xFF0C;&#x5927;&#x5C0F;5&#xFF0C;&#x521D;&#x59CB;&#x503C;&#x4E3A;&quot;a&quot;

// Set 
val set: Set<span class="hljs-tag">&lt;<span class="hljs-name">Any</span>&gt;</span> = setOf<span class="hljs-tag">&lt;<span class="hljs-name">Any</span>&gt;</span>(1, &quot;2&quot;, 3, &quot;3&quot;)

// Map 
val map: Map<span class="hljs-tag">&lt;<span class="hljs-name">String,</span> <span class="hljs-attr">Any</span>&gt;</span> = mapOf(&quot;k1&quot; to &quot;v1&quot; , &quot;k2&quot; to 3)

indices
</code></pre>
<pre><code class="lang-xml">//collection.joinToString(xxx)
&#x5BF9;&#x96C6;&#x5408;&#x4E2D;&#x7684;&#x5143;&#x7D20;&#x8FDB;&#x884C;&#x7B80;&#x5355;&#x7684;&#x62FC;&#x63A5;

// collection.any(XXX)
Returns `true` if at least one element matches the given [predicate].
</code></pre>
<h2 id="&#x7A7A;&#x6307;&#x9488;"><a name="&#x7A7A;&#x6307;&#x9488;" class="anchor-navigation-ex-anchor" href="#&#x7A7A;&#x6307;&#x9488;"><i class="fa fa-link" aria-hidden="true"></i></a>1.8. &#x7A7A;&#x6307;&#x9488;</h2>
<p>kotlin&#x53EA;&#x662F;&#x5728;&#x7F16;&#x8BD1;&#x7684;&#x65F6;&#x5019;&#x52A0;&#x5F3A;&#x4E86;&#x7A7A;&#x6307;&#x9488;&#x7684;&#x68C0;&#x67E5;&#xFF0C;&#x6700;&#x540E;&#x8FD8;&#x662F;&#x8981;&#x5224;&#x65AD;&#x662F;&#x5426;&#x4E3A;&#x7A7A;&#x624D;&#x80FD;&#x6700;&#x7EC8;&#x4F7F;&#x7528;&#x3002;&#x5375;&#x7528;&#x3002;</p>
<pre><code class="lang-java"><span class="hljs-comment">//?  &#x8868;&#x793A;&#x53EF;&#x4E3A;null</span>
var ageString : String ?
<span class="hljs-comment">//?.    &#x4E3A;&#x7A7A;&#x5C31;&#x8FD4;&#x56DE;null &#xFF0C;&#x4E0D;&#x662F;&#x7A7A; &#x5C31;&#x8FD4;&#x56DE; &#x5BF9;&#x5E94;&#x7684;&#x503C;</span>
ageString =student ?. name

<span class="hljs-comment">// ?:  ageString &#x4E3A;&#x7A7A;&#x5C31;&#x7528;&#x9ED8;&#x8BA4;&#x503C; &#xFF0C;&#x5426;&#x5219;&#x7528;&#x53D6;&#x5F97;&#x7684;&#x503C;</span>
var info :String?
info =  ageString ?:  <span class="hljs-string">&quot;21&quot;</span>

<span class="hljs-comment">// !!  &#x975E;&#x7A7A;&#x65AD;&#x8A00; ageString&#x4E0D;&#x4E3A;&#x7A7A;&#x65F6;&#x83B7;&#x53D6;&#x5BF9;&#x5E94;&#x7684;&#x503C; &#xFF0C;&#x5426;&#x5219;&#x76F4;&#x63A5;&#x62A5;&#x9519; &#x3002;</span>
val length : Int  = ageString!!.length

<span class="hljs-comment">// &#x5224;&#x65AD;&#x662F;&#x5426;&#x4E3A;&#x7A7A;</span>
var flag : Boolean = ageString.isNullOrBlank()
</code></pre>
<h2 id="&#x6807;&#x7B7E;"><a name="&#x6807;&#x7B7E;" class="anchor-navigation-ex-anchor" href="#&#x6807;&#x7B7E;"><i class="fa fa-link" aria-hidden="true"></i></a>1.9. @&#x6807;&#x7B7E;</h2>
<pre><code class="lang-text">## return@
return@XXlabel &#x8BED;&#x6CD5;&#x7528;&#x4E8E;&#x6307;&#x5B9A;&#x6B64;&#x8BED;&#x53E5;&#x4ECE;&#x51E0;&#x4E2A;&#x5D4C;&#x5957;&#x51FD;&#x6570;&#x4E2D;&#x8FD4;&#x56DE;&#x54EA;&#x4E2A;&#x51FD;&#x6570;&#x3002;
</code></pre>
<h2 id="&#x7C7B;&#x578B;&#x8F6C;&#x6362;"><a name="&#x7C7B;&#x578B;&#x8F6C;&#x6362;" class="anchor-navigation-ex-anchor" href="#&#x7C7B;&#x578B;&#x8F6C;&#x6362;"><i class="fa fa-link" aria-hidden="true"></i></a>1.10. &#x7C7B;&#x578B;&#x8F6C;&#x6362;</h2>
<pre><code class="lang-java">var info : String = <span class="hljs-string">&quot;100&quot;</span>
var info2 :Int = info.toInt()
var info3 :String = info2.toString()
</code></pre>
<h2 id="&#x5BF9;&#x8C61;"><a name="&#x5BF9;&#x8C61;" class="anchor-navigation-ex-anchor" href="#&#x5BF9;&#x8C61;"><i class="fa fa-link" aria-hidden="true"></i></a>1.11. &#x5BF9;&#x8C61;</h2>
<p>&#x6240;&#x6709;&#x7684;&#x7C7B;&#x90FD;&#x7EE7;&#x627F;&#x81EA; Any &#x3002;
&#x9ED8;&#x8BA4;&#x6240;&#x6709;&#x7684;&#x7C7B;&#x90FD;&#x662F;final&#x7C7B;&#x578B; &#x3002;</p>
<pre><code class="lang-xml">// (info: String) &#x662F;&#x4E3B;&#x6784;&#x65B9;&#x6CD5;
open  class Person  (info: String){
   // &#x53EF;&#x4EE5;&#x88AB;&#x91CD;&#x5199;
   open var info : String =&quot;&#x4EBA;&#x7C7B;&quot;
   var age1 : Int = 25

   // &#x6B21;&#x6784;&#x9020;&#x51FD;&#x6570;
  constructor(info: String  ,age: Int) : this(info) {
       this. info = info
       this.age1 = age
   }
   // open &#x666E;&#x901A;&#x51FD;&#x6570;   ,&#x53EF;&#x4EE5;&#x88AB;&#x91CD;&#x65B0;
   open fun showInfo(){
   }

   // &#x666E;&#x901A;&#x51FD;&#x6570; &#x4E0D;&#x53EF;&#x4EE5;&#x88AB;&#x91CD;&#x65B0;
   fun showInfo2(){
   }
}

public class Student(info: String) : Person(info) {
    override var info : String =info

    // &#x6B21;&#x6784;&#x9020;&#x51FD;&#x6570;
    constructor(info: String  ,age: Int) : this(info) {
        this. info = info
        this.age1 = age
    }

    // override &#x91CD;&#x5199;&#x51FD;&#x6570;
    override fun showInfo() {
        super.showInfo()
    }

}

// &#x6D4B;&#x8BD5;
var student1 : Student = Student(&quot;&#x65B0;&#x4EBA;&#x7C7B;&quot;  ,19)
var student2 : Student = Student(&quot;&#x65B0;&#x4EBA;&#x7C7B;&quot;   )
</code></pre>
<h2 id="&#x63A5;&#x53E3;"><a name="&#x63A5;&#x53E3;" class="anchor-navigation-ex-anchor" href="#&#x63A5;&#x53E3;"><i class="fa fa-link" aria-hidden="true"></i></a>1.12. &#x63A5;&#x53E3;</h2>
<pre><code class="lang-java"><span class="hljs-class"><span class="hljs-keyword">interface</span>  <span class="hljs-title">Language</span>  </span>{
    <span class="hljs-function">fun <span class="hljs-title">chinease</span><span class="hljs-params">(msg :String )</span>
    fun <span class="hljs-title">english</span><span class="hljs-params">(msg :String )</span>
}

<span class="hljs-comment">// Person &#x662F;&#x7236;&#x7C7B; &#xFF0C; Language&#x662F;&#x63A5;&#x53E3;</span>
<span class="hljs-keyword">public</span> class <span class="hljs-title">Student</span><span class="hljs-params">(info: String)</span> : <span class="hljs-title">Person</span><span class="hljs-params">(info)</span>,Language</span>{
    <span class="hljs-function">override fun <span class="hljs-title">english</span><span class="hljs-params">(msg: String)</span> </span>{
    }

    <span class="hljs-function">override fun <span class="hljs-title">chinease</span><span class="hljs-params">(msg: String)</span> </span>{
    }
    ....
}
</code></pre>
<h2 id="&#x7C7B;&#x521D;&#x59CB;&#x5316;"><a name="&#x7C7B;&#x521D;&#x59CB;&#x5316;" class="anchor-navigation-ex-anchor" href="#&#x7C7B;&#x521D;&#x59CB;&#x5316;"><i class="fa fa-link" aria-hidden="true"></i></a>1.13. &#x7C7B;&#x521D;&#x59CB;&#x5316;</h2>
<pre><code class="lang-java">kotlin&#x589E;&#x52A0;&#x4E86;&#x4E00;&#x4E2A;&#x65B0;&#x7684;&#x5173;&#x952E;&#x5B57;init&#x7528;&#x6765;&#x5904;&#x7406;&#x7C7B;&#x7684;&#x521D;&#x59CB;&#x5316;&#x95EE;&#x9898;&#xFF0C;
init&#x6A21;&#x5757;&#x4E2D;&#x7684;&#x5185;&#x5BB9;&#x53EF;&#x4EE5;&#x76F4;&#x63A5;&#x4F7F;&#x7528;&#x6784;&#x9020;&#x51FD;&#x6570;&#x7684;&#x53C2;&#x6570;&#x3002;
</code></pre>
<h2 id="apply"><a name="apply" class="anchor-navigation-ex-anchor" href="#apply"><i class="fa fa-link" aria-hidden="true"></i></a>1.14. apply</h2>
<pre><code class="lang-java">&#x8C03;&#x7528;&#x5BF9;&#x8C61;&#x7684;apply&#x51FD;&#x6570;&#xFF0C;&#x5728;&#x51FD;&#x6570;&#x8303;&#x56F4;&#x5185;&#xFF0C;&#x53EF;&#x4EE5;&#x4EFB;&#x610F;&#x8C03;&#x7528;&#x8BE5;&#x5BF9;&#x8C61;&#x7684;&#x4EFB;&#x610F;&#x65B9;&#x6CD5;&#xFF0C;&#x5E76;&#x8FD4;&#x56DE;&#x8BE5;&#x5BF9;&#x8C61;&#x3002;
</code></pre>
<h2 id="with"><a name="with" class="anchor-navigation-ex-anchor" href="#with"><i class="fa fa-link" aria-hidden="true"></i></a>1.15. with</h2>
<pre><code class="lang-java">&#x5C06;&#x5BF9;&#x8C61;&#x4F5C;&#x4E3A;&#x51FD;&#x6570;&#x7684;&#x53C2;&#x6570;&#xFF0C;&#x5728;&#x51FD;&#x6570;&#x5185;&#x53EF;&#x4EE5;&#x901A;&#x8FC7; <span class="hljs-keyword">this</span>&#x6307;&#x4EE3;&#x8BE5;&#x5BF9;&#x8C61;&#x3002;
&#x8FD4;&#x56DE;&#x503C;&#x4E3A;&#x51FD;&#x6570;&#x7684;&#x6700;&#x540E;&#x4E00;&#x884C;&#x6216;<span class="hljs-keyword">return</span>&#x8868;&#x8FBE;&#x5F0F;
</code></pre>
<h2 id="when"><a name="when" class="anchor-navigation-ex-anchor" href="#when"><i class="fa fa-link" aria-hidden="true"></i></a>1.16. when</h2>
<pre><code class="lang-java">&#x8868;&#x8FBE;&#x5F0F;&#x7C7B;&#x4F3C; java &#x4E2D;&#x7684; <span class="hljs-keyword">switch</span> .
&#x53EF;&#x4EE5;&#x7528;when&#x66FF;&#x6362;&#x590D;&#x6742;&#x7684;<span class="hljs-keyword">if</span>/<span class="hljs-keyword">else</span>&#x8BED;&#x53E5; &#x3002;
&#x5728;when&#x4E2D;&#xFF0C;<span class="hljs-keyword">else</span>&#x540C;<span class="hljs-keyword">switch</span>&#x7684;<span class="hljs-keyword">default</span>&#x3002;&#x8FD9;&#x662F;&#x4F60;&#x7ED9;&#x51FA;&#x7684;&#x5F53;&#x4F60;&#x7684;&#x8868;&#x8FBE;&#x5F0F;&#x6CA1;&#x6709;&#x8986;&#x76D6;&#x60C5;&#x51B5;&#x4E0B;&#x7684;&#x89E3;&#x51B3;&#x65B9;&#x6848;&#x3002;
</code></pre>
<h2 id="intarrayof"><a name="intarrayof" class="anchor-navigation-ex-anchor" href="#intarrayof"><i class="fa fa-link" aria-hidden="true"></i></a>1.17. intArrayOf</h2>
<pre><code class="lang-java">&#x521B;&#x5EFA;&#x4E00;&#x4E2A;<span class="hljs-keyword">int</span>&#x6570;&#x7EC4;
</code></pre>
<h2 id="&#x4F4D;&#x8FD0;&#x7B97;&#x7B26;"><a name="&#x4F4D;&#x8FD0;&#x7B97;&#x7B26;" class="anchor-navigation-ex-anchor" href="#&#x4F4D;&#x8FD0;&#x7B97;&#x7B26;"><i class="fa fa-link" aria-hidden="true"></i></a>1.18. &#x4F4D;&#x8FD0;&#x7B97;&#x7B26;</h2>
<pre><code class="lang-java">shl  &#x2014;&#x2014; &#x7C7B;&#x4F3C;Java&#x7684;&lt;&lt;
shr  &#x2014;&#x2014; &#x7C7B;&#x4F3C;Java&#x7684;&gt;&gt;
ushr &#x2014;&#x2014; &#x7C7B;&#x4F3C;Java&#x7684;&gt;&gt;&gt;
and  &#x2014;&#x2014; &#x7C7B;&#x4F3C;Java&#x7684;&amp;
or   &#x2014;&#x2014; &#x7C7B;&#x4F3C;Java&#x7684;|
xor  &#x2014;&#x2014;  &#x540C;Java&#x4E2D;&#x7684;&#x6309;&#x4F4D;&#x5F02;&#x6216; ^
inv  &#x2014;&#x2014; Java&#x4E2D;&#x7684;&#x6309;&#x4F4D;&#x53D6;&#x53CD; -
</code></pre>
<h2 id="&#x5FAA;&#x73AF;"><a name="&#x5FAA;&#x73AF;" class="anchor-navigation-ex-anchor" href="#&#x5FAA;&#x73AF;"><i class="fa fa-link" aria-hidden="true"></i></a>1.19. &#x5FAA;&#x73AF;</h2>
<pre><code class="lang-xml">for(i in 0..9){
    // [0,9]
}

(0 until 9){
    // [0,9)
}
</code></pre>
<h2 id="mapto"><a name="mapto" class="anchor-navigation-ex-anchor" href="#mapto"><i class="fa fa-link" aria-hidden="true"></i></a>1.20. mapTo</h2>
<pre><code class="lang-xml">// mapTo &#x4E0E;&#x5FAA;&#x73AF;&#x642D;&#x914D;&#x4F7F;&#x7528;&#x3002;&#x6B64;&#x5904;&#x7684;&#x89E3;&#x91CA;&#x662F;&#xFF1A;
// [0 ,size)&#x4E2D;&#x5FAA;&#x73AF;&#x53D6;&#x7D22;&#x5F15;i &#xFF0C;&#x65B0;&#x5EFA;BeanB&#x5BF9;&#x8C61;&#xFF0C;&#x5E76;&#x5C06;&#x8FD9;&#x4E9B;&#x5BF9;&#x8C61;&#x5168;&#x90E8;&#x6DFB;&#x52A0;&#x5230;&#x96C6;&#x5408; listA&#x4E2D; 
(0 until mTitles.size)
        .mapTo( listA) {
                   BeanB( array1[it],  array2[it] ) 
        }
</code></pre>
<h2 id="&#x4E09;&#x76EE;&#x8868;&#x8FBE;&#x5F0F;"><a name="&#x4E09;&#x76EE;&#x8868;&#x8FBE;&#x5F0F;" class="anchor-navigation-ex-anchor" href="#&#x4E09;&#x76EE;&#x8868;&#x8FBE;&#x5F0F;"><i class="fa fa-link" aria-hidden="true"></i></a>1.21. &#x4E09;&#x76EE;&#x8868;&#x8FBE;&#x5F0F;</h2>
<p>kotlin&#x4E0D;&#x652F;&#x6301;&#x3002; &#x8BF7;&#x76F4;&#x63A5;&#x4F7F;&#x7528; if else&#x6765;&#x4EE3;&#x66FF;</p>
<h2 id="data"><a name="data" class="anchor-navigation-ex-anchor" href="#data"><i class="fa fa-link" aria-hidden="true"></i></a>1.22. data</h2>
<p>data class  ,  &#x5728; Kotlin &#x4E2D;&#xFF0C;&#x4E0D;&#x9700;&#x8981;&#x81EA;&#x5DF1;&#x52A8;&#x624B;&#x53BB;&#x5199;&#x4E00;&#x4E2A; JavaBean&#xFF0C;&#x53EF;&#x4EE5;&#x76F4;&#x63A5;&#x4F7F;&#x7528; DataClass&#xFF0C;&#x4F7F;&#x7528; DataClass &#x7F16;&#x8BD1;&#x5668;&#x4F1A;&#x9ED8;&#x9ED8;&#x5730;&#x5E2E;&#x6211;&#x4EEC;&#x751F;&#x6210;&#x4EE5;&#x4E0B;&#x51FD;&#x6570; &#x3002; &#x5176;&#x5B9E;&#x4E0D;&#x65B9;&#x4FBF;&#xFF0C;&#x4E0D;&#x63A8;&#x8350;&#x4F7F;&#x7528;&#x3002;</p>
<h2 id="let"><a name="let" class="anchor-navigation-ex-anchor" href="#let"><i class="fa fa-link" aria-hidden="true"></i></a>1.23. let</h2>
<pre><code class="lang-java">&#x5E38;&#x4E0E;&#x975E;&#x7A7A;&#x5224;&#x65AD;&#x7B26;?. &#x4E00;&#x8D77;&#x4F7F;&#x7528;
mSurfaceTexture?.let {
    <span class="hljs-comment">// compoundDrawables &#x4E0D;&#x4E3A;&#x7A7A;&#x5C31;&#x6267;&#x884C;...</span>
    <span class="hljs-comment">// it &#x662F;&#x6307; mSurfaceTexture</span>
   mCamera?.setSurfaceTexture(it)  
}
</code></pre>
<h2 id="&#x53CC;&#x5192;&#x53F7;-"><a name="&#x53CC;&#x5192;&#x53F7;-" class="anchor-navigation-ex-anchor" href="#&#x53CC;&#x5192;&#x53F7;-"><i class="fa fa-link" aria-hidden="true"></i></a>1.24. &#x53CC;&#x5192;&#x53F7; ::</h2>
<pre><code class="lang-java"><span class="hljs-comment">// &#x8C03;&#x7528;d&#x5BF9;&#x8C61;&#x7684;&#x65B9;&#x6CD5;getResult</span>
d::getResult
</code></pre>
<h3 id="&#x539F;&#x751F;&#x5B57;&#x7B26;&#x4E32;--&#x4E09;&#x5F15;&#x53F7;"><a name="&#x539F;&#x751F;&#x5B57;&#x7B26;&#x4E32;--&#x4E09;&#x5F15;&#x53F7;" class="anchor-navigation-ex-anchor" href="#&#x539F;&#x751F;&#x5B57;&#x7B26;&#x4E32;--&#x4E09;&#x5F15;&#x53F7;"><i class="fa fa-link" aria-hidden="true"></i></a>1.24.1. &#x539F;&#x751F;&#x5B57;&#x7B26;&#x4E32;  &#x4E09;&#x5F15;&#x53F7;</h3>
<pre><code class="lang-java"><span class="hljs-function">A raw string is delimited by a triple <span class="hljs-title">quote</span> <span class="hljs-params">(<span class="hljs-string">&quot;&quot;</span><span class="hljs-string">&quot; xxx &quot;</span><span class="hljs-string">&quot;&quot;</span>)</span>,
 contains no escaping and can contain newlines and any other characters.
val str:String</span>= <span class="hljs-string">&quot;&quot;</span><span class="hljs-string">&quot; the price is$\d 199 &quot;</span><span class="hljs-string">&quot;&quot;</span>
</code></pre>
<h2 id="&#x7EE7;&#x627F;"><a name="&#x7EE7;&#x627F;" class="anchor-navigation-ex-anchor" href="#&#x7EE7;&#x627F;"><i class="fa fa-link" aria-hidden="true"></i></a>1.25. &#x7EE7;&#x627F;</h2>
<p>Kotlin &#x4E2D;&#x6240;&#x6709;&#x7C7B;&#x90FD;&#x7EE7;&#x627F;&#x8BE5; Any&#x7C7B;&#xFF0C;Any&#x662F;&#x6240;&#x6709;&#x7C7B;&#x7684;&#x8D85;&#x7C7B;&#x3002;
&#x5982;&#x679C;&#x4E00;&#x4E2A;&#x7C7B;&#x8981;&#x88AB;&#x7EE7;&#x627F;&#xFF0C;&#x9700;&#x8981;&#x7528;open &#x5173;&#x952E;&#x5B57;&#x8FDB;&#x884C;&#x4FEE;&#x9970;&#x3002;</p>
<h2 id="&#x51FD;&#x6570;&#x91CD;&#x5199;&#x3001;&#x5C5E;&#x6027;&#x91CD;&#x5199;"><a name="&#x51FD;&#x6570;&#x91CD;&#x5199;&#x3001;&#x5C5E;&#x6027;&#x91CD;&#x5199;" class="anchor-navigation-ex-anchor" href="#&#x51FD;&#x6570;&#x91CD;&#x5199;&#x3001;&#x5C5E;&#x6027;&#x91CD;&#x5199;"><i class="fa fa-link" aria-hidden="true"></i></a>1.26. &#x51FD;&#x6570;&#x91CD;&#x5199;&#x3001;&#x5C5E;&#x6027;&#x91CD;&#x5199;</h2>
<p>&#x5728;&#x57FA;&#x7C7B;&#x4E2D;&#xFF0C;&#x4F7F;&#x7528;fun&#x58F0;&#x660E;&#x51FD;&#x6570;&#x65F6;&#xFF0C;&#x9ED8;&#x8BA4;&#x4E0D;&#x80FD;&#x88AB;&#x5B50;&#x7C7B;&#x91CD;&#x5199;&#x3002;&#x5982;&#x679C;&#x9700;&#x8981;&#x88AB;&#x5B50;&#x7C7B;&#x91CD;&#x5199;&#x3002; &#x9700;&#x8981;&#x7528;open&#x4FEE;&#x9970;&#x5B83;, &#x7136;&#x540E;&#x5B50;&#x7C7B;&#x91CD;&#x5199;&#x65B9;&#x6CD5;&#x4F7F;&#x7528; override &#x8BF4;&#x660E; &#x3002;</p>
<h2 id="&#x62D3;&#x5C55;&#x51FD;&#x6570;"><a name="&#x62D3;&#x5C55;&#x51FD;&#x6570;" class="anchor-navigation-ex-anchor" href="#&#x62D3;&#x5C55;&#x51FD;&#x6570;"><i class="fa fa-link" aria-hidden="true"></i></a>1.27. &#x62D3;&#x5C55;&#x51FD;&#x6570;</h2>
<p>&#x5982;&#x679C;&#x4E00;&#x4E2A;&#x7C7B;&#x6CA1;&#x6709;&#x5B9A;&#x4E49;&#x67D0;&#x4E2A;&#x529F;&#x80FD;&#xFF0C;&#x53EF;&#x4EE5;&#x5728;&#x7C7B;&#x5916;&#xFF08;&#x5177;&#x4F53;&#x4F7F;&#x7528;&#x7684;&#x5730;&#x65B9;&#xFF09;&#x5199;&#x4E00;&#x4E2A;&#x62D3;&#x5C55;&#x51FD;&#x6570;&#x3002;&#x62D3;&#x5C55;&#x51FD;&#x6570;&#x540D;&#x53EF;&#x4EE5;&#x8DDF;&#x7C7B;&#x7684;&#x539F;&#x6709;&#x51FD;&#x6570;&#x540D;&#x5B57;&#x76F8;&#x540C;&#xFF0C;&#x4F46;&#x662F;&#x4F1A;&#x4F18;&#x5148;&#x4F7F;&#x7528;&#x7C7B;&#x7684;&#x539F;&#x6709;&#x51FD;&#x6570;&#x3002;
&#x7A7A;&#x5BF9;&#x8C61;&#x4E5F;&#x53EF;&#x4EE5;&#x4F7F;&#x7528;&#x62D3;&#x5C55;&#x51FD;&#x6570;&#x3002; this&#x6307;&#x7684;&#x662F;&#x88AB;&#x6539;&#x9020;&#x7684;&#x90A3;&#x4E2A;&#x5BF9;&#x8C61;&#x662F;&#x4F8B;&#x3002;</p>
<pre><code class="lang-xml">class User(var name:String)

/**&#x6269;&#x5C55;&#x51FD;&#x6570;**/
fun User.Print(){
    print(&quot;&#x7528;&#x6237;&#x540D; $name&quot;)
}

fun main(arg:Array<span class="hljs-tag">&lt;<span class="hljs-name">String</span>&gt;</span>){
    var user = User(&quot;Runoob&quot;)
    user.Print()
}
</code></pre>
<h2 id="&#x4F34;&#x751F;&#x5BF9;&#x8C61;"><a name="&#x4F34;&#x751F;&#x5BF9;&#x8C61;" class="anchor-navigation-ex-anchor" href="#&#x4F34;&#x751F;&#x5BF9;&#x8C61;"><i class="fa fa-link" aria-hidden="true"></i></a>1.28. &#x4F34;&#x751F;&#x5BF9;&#x8C61;</h2>
<p>Kotlin&#x79FB;&#x9664;&#x4E86;static&#x7684;&#x6982;&#x5FF5;&#x3002;
&#x901A;&#x5E38;&#x7528; object &#x548C; companion object  &#x6765;&#x5B9E;&#x73B0;</p>
<pre><code class="lang-xml">&#x4F7F;&#x7528;&quot;object&quot;&#x4FEE;&#x9970;&#x9759;&#x6001;&#x7C7B;
&#x88AB;&#x4FEE;&#x9970;&#x7684;&#x7C7B;&#xFF0C;&#x53EF;&#x4EE5;&#x4F7F;&#x7528;&#x7C7B;&#x540D;.&#x65B9;&#x6CD5;&#x540D;&#x7684;&#x5F62;&#x5F0F;&#x8C03;&#x7528;
var version_name1 = Util.getName()
object Util {
    fun getName(): String {
        return BuildConfig.VERSION_NAME
    }
}


&#x4F7F;&#x7528;&quot;companion object&quot;&#x4FEE;&#x9970;&#x9759;&#x6001;&#x65B9;&#x6CD5;
&#x53EF;&#x4EE5;&#x4F7F;&#x7528;&#x7C7B;&#x540D;.&#x65B9;&#x6CD5;&#x540D;&#x7684;&#x5F62;&#x5F0F;&#x8C03;&#x7528;
var version_name2 = Util2.getName()
class Util2 {
    companion object {
        fun getName(): String {
            return BuildConfig.VERSION_NAME
        }
    }
}
</code></pre>
<h2 id="&#x6570;&#x636E;&#x7C7B;"><a name="&#x6570;&#x636E;&#x7C7B;" class="anchor-navigation-ex-anchor" href="#&#x6570;&#x636E;&#x7C7B;"><i class="fa fa-link" aria-hidden="true"></i></a>1.29. &#x6570;&#x636E;&#x7C7B;</h2>
<p>kotlin&#x7684;&#x6570;&#x636E;&#x7C7B; &#x7C7B;&#x4F3C;java&#x4E2D;&#x624B;&#x52A8;&#x521B;&#x5EFA;&#x7684; javaBean &#xFF0C;&#x7528;&#x6765;&#x4F20;&#x9012;&#x6570;&#x636E; &#x3002;
&#x7528;&#x5173;&#x952E;&#x5B57; data &#x7533;&#x660E;&#x3002; &#x6570;&#x636E;&#x7C7B;&#x4E0D;&#x80FD;&#x7EE7;&#x627F;&#x5176;&#x4ED6;&#x7C7B;&#xFF08;&#x53EF;&#x4EE5;&#x5B9E;&#x73B0;&#x5176;&#x4ED6;&#x63A5;&#x53E3;&#xFF09; &#x3002;
&#x5728;&#x4F7F;&#x7528;&#x6570;&#x636E;&#x7C7B;&#x65F6;&#xFF0C;&#x4E0E;&#x666E;&#x901A;&#x7C7B;&#x65E0;&#x5F02; &#x3002;</p>
<h2 id="&#x5BC6;&#x5C01;&#x7C7B;"><a name="&#x5BC6;&#x5C01;&#x7C7B;" class="anchor-navigation-ex-anchor" href="#&#x5BC6;&#x5C01;&#x7C7B;"><i class="fa fa-link" aria-hidden="true"></i></a>1.30. &#x5BC6;&#x5C01;&#x7C7B;</h2>
<p>&#x7528;&#x5173;&#x952E;&#x5B57; sealed &#x7533;&#x660E;&#x3002;
&#x5BC6;&#x5C01;&#x7C7B;&#x5C31;&#x50CF;&#x4E00;&#x4E2A;&#x66F4;&#x5F3A;&#x5927;&#x7684;&#x679A;&#x4E3E;&#x3002;&#x5BC6;&#x5C01;&#x7C7B;&#x53EA;&#x6709;&#x56FA;&#x5B9A;&#x5B50;&#x7C7B; &#x3002;</p>
<h2 id="&#x679A;&#x4E3E;"><a name="&#x679A;&#x4E3E;" class="anchor-navigation-ex-anchor" href="#&#x679A;&#x4E3E;"><i class="fa fa-link" aria-hidden="true"></i></a>1.31. &#x679A;&#x4E3E;</h2>
<pre><code class="lang-xml">enum class Color{
    RED,BLACK
}

&#x679A;&#x4E3E;&#x53EF;&#x4EE5;&#x88AB;&#x521D;&#x59CB;&#x5316;
enum class Color(val rgb: Int) {
    RED(0xFF0000),
    GREEN(0x00FF00)
}
</code></pre>
<h2 id="&#x6302;&#x8D77;&#x51FD;&#x6570;"><a name="&#x6302;&#x8D77;&#x51FD;&#x6570;" class="anchor-navigation-ex-anchor" href="#&#x6302;&#x8D77;&#x51FD;&#x6570;"><i class="fa fa-link" aria-hidden="true"></i></a>1.32. &#x6302;&#x8D77;&#x51FD;&#x6570;</h2>
<pre><code class="lang-xml">&#x7528; Suspend &#x4FEE;&#x9970;
&#x7B49;xx&#x51FD;&#x6570;&#x6267;&#x884C;&#x5B8C;&#x624D;&#x4F1A;&#x8F93;&#x5165;&#x67D0;&#x4E2A;&#x7ED3;&#x679C;&#x3002; &#x4F46;&#x662F;&#x7EBF;&#x7A0B;&#x5E76;&#x4E0D;&#x4F1A;&#x963B;&#x585E;&#x3002;
&#x7C7B;&#x4F3C;&#x56DE;&#x8C03;&#x7684;&#x4F7F;&#x7528;
</code></pre>
<h2 id="&#x534F;&#x7A0B;"><a name="&#x534F;&#x7A0B;" class="anchor-navigation-ex-anchor" href="#&#x534F;&#x7A0B;"><i class="fa fa-link" aria-hidden="true"></i></a>1.33. &#x534F;&#x7A0B;</h2>
<pre><code class="lang-xml">&#x53EF;&#x4EE5;&#x7528;&#x534F;&#x7A0B;&#x66FF;&#x6362;Thread&#x7684;&#x4F5C;&#x7528;&#x3002;
&#x534F;&#x7A0B;&#x53EF;&#x4EE5;&#x770B;&#x4F5C;&#x662F;&#x4E00;&#x4E2A;&#x8F7B;&#x91CF;&#x7EA7;&#x7684;&#x7EBF;&#x7A0B;&#xFF0C;
&#x5B83;&#x4E0D;&#x662F;&#x7531;&#x64CD;&#x4F5C;&#x7CFB;&#x7EDF;&#x6216;&#x662F;&#x865A;&#x62DF;&#x673A;&#x6765;&#x5B9E;&#x73B0;&#x7684;&#xFF0C;&#x800C;&#x662F;&#x901A;&#x8FC7;&#x7F16;&#x8BD1;&#x5668;&#x3002;
&#x8FD9;&#x610F;&#x5473;&#x7740;&#x76F8;&#x5BF9;&#x4E8E;&#x7EBF;&#x7A0B;&#xFF0C;&#x534F;&#x7A0B;&#x7684;&#x5F00;&#x9500;&#x66F4;&#x5C0F;&#x3002;
</code></pre>
<h2 id="&#x547D;&#x540D;&#x53C2;&#x6570;-&#x3001;-&#x9ED8;&#x8BA4;&#x53C2;&#x6570;"><a name="&#x547D;&#x540D;&#x53C2;&#x6570;-&#x3001;-&#x9ED8;&#x8BA4;&#x53C2;&#x6570;" class="anchor-navigation-ex-anchor" href="#&#x547D;&#x540D;&#x53C2;&#x6570;-&#x3001;-&#x9ED8;&#x8BA4;&#x53C2;&#x6570;"><i class="fa fa-link" aria-hidden="true"></i></a>1.34. &#x547D;&#x540D;&#x53C2;&#x6570; &#x3001; &#x9ED8;&#x8BA4;&#x53C2;&#x6570;</h2>
<pre><code class="lang-xml">&#x51FD;&#x6570;&#x5B9A;&#x4E49;&#xFF1A;&#x7B2C;&#x4E00;&#x4E2A;&#x53C2;&#x6570;&#x6CA1;&#x6709;&#x9ED8;&#x8BA4;&#x503C;&#xFF0C;&#x540E;&#x9762;&#x7684;&#x90FD;&#x6709;&#x9ED8;&#x8BA4;&#x503C;
fun reformat(str: String,  
            normalizeCase: Boolean = true,
            upperCaseFirstLetter: Boolean = true,
            divideByCamelHumps: Boolean = false,  
            wordSeparator: String= &quot;bbb&quot;)
{
  // ....
}


//&#x4E0D;&#x4F1A;&#x5F15;&#x8D77;&#x6B67;&#x4E49;&#x7684;&#x65F6;&#x5019;&#x8C03;&#x7528; (&#x5168;&#x90E8;&#x4F7F;&#x7528;&#x9ED8;&#x8BA4;&#x503C;)
reformat(&quot;tom&quot;)
//&#x6709;&#x6B67;&#x4E49;&#x65F6;&#xFF0C;&#x5FC5;&#x987B;&#x8981;&#x6307;&#x5B9A;&#x53C2;&#x6570;&#x540D;&#x5B57;&#x3002; &#x6307;&#x5B9A;&#x547D;&#x540D;&#x3002;&#x5426;&#x5219;&#x4E0D;&#x77E5;&#x9053;&#x4F60;&#x8981;&#x5C06;&#x503C;&#x8D4B;&#x7ED9;&#x8C01;
reformat(&quot;tom&quot; , upperCaseFirstLetter= false)
</code></pre>
<h2 id="kotlin-main-&#x5165;&#x53E3;&#x51FD;&#x6570;"><a name="kotlin-main-&#x5165;&#x53E3;&#x51FD;&#x6570;" class="anchor-navigation-ex-anchor" href="#kotlin-main-&#x5165;&#x53E3;&#x51FD;&#x6570;"><i class="fa fa-link" aria-hidden="true"></i></a>1.35. kotlin main &#x5165;&#x53E3;&#x51FD;&#x6570;</h2>
<pre><code class="lang-xml">fun main(args: Array<span class="hljs-tag">&lt;<span class="hljs-name">String</span>&gt;</span>){
    println(&quot;hello kotlin&quot;)
}
</code></pre>
<h2 id="kotlin-&#x8C03;&#x7528;-java"><a name="kotlin-&#x8C03;&#x7528;-java" class="anchor-navigation-ex-anchor" href="#kotlin-&#x8C03;&#x7528;-java"><i class="fa fa-link" aria-hidden="true"></i></a>1.36. kotlin &#x8C03;&#x7528; java</h2>
<pre><code class="lang-xml">val javaDemo =  JavaDemo() //&#x65B0;&#x5EFA;&#x5BF9;&#x8C61;
val msg =javaDemo.helloMsg // &#x8C03;&#x7528;&#x5BF9;&#x8C61;&#x7684;&#x65B9;&#x6CD5;
println(&quot;msg=&quot;+ msg)
</code></pre>
<h2 id="java&#x8C03;&#x7528;kotlin&#x4EE3;&#x7801;"><a name="java&#x8C03;&#x7528;kotlin&#x4EE3;&#x7801;" class="anchor-navigation-ex-anchor" href="#java&#x8C03;&#x7528;kotlin&#x4EE3;&#x7801;"><i class="fa fa-link" aria-hidden="true"></i></a>1.37. java&#x8C03;&#x7528;kotlin&#x4EE3;&#x7801;</h2>
<pre><code class="lang-java"><span class="hljs-comment">// Companion &#x662F;&#x5173;&#x952E;&#x5B57; &#xFF0C; newInstance &#x662F;kotlin&#x4E2D;&#x7684;&#x9759;&#x6001;&#x65B9;&#x6CD5;</span>
mFragments[FIRST] = DeviceFragment.Companion.newInstance();
</code></pre>
<h2 id="init"><a name="init" class="anchor-navigation-ex-anchor" href="#init"><i class="fa fa-link" aria-hidden="true"></i></a>1.38. init</h2>
<p>kotlin&#x589E;&#x52A0;&#x4E86;&#x4E00;&#x4E2A;&#x65B0;&#x7684;&#x5173;&#x952E;&#x5B57; init &#x7528;&#x6765;&#x5904;&#x7406;&#x7C7B;&#x7684;&#x521D;&#x59CB;&#x5316;&#x95EE;&#x9898;&#xFF0C;init&#x6A21;&#x5757;&#x4E2D;&#x7684;&#x5185;&#x5BB9;&#x53EF;&#x4EE5;&#x76F4;&#x63A5;&#x4F7F;&#x7528;&#x6784;&#x9020;&#x51FD;&#x6570;&#x7684;&#x53C2;&#x6570;&#x3002;</p>
<h2 id="&#x5BF9;&#x8C61;&#x8868;&#x8FBE;&#x5F0F;"><a name="&#x5BF9;&#x8C61;&#x8868;&#x8FBE;&#x5F0F;" class="anchor-navigation-ex-anchor" href="#&#x5BF9;&#x8C61;&#x8868;&#x8FBE;&#x5F0F;"><i class="fa fa-link" aria-hidden="true"></i></a>1.39. &#x5BF9;&#x8C61;&#x8868;&#x8FBE;&#x5F0F;</h2>
<p>&#x5BF9;&#x8C61;&#x8868;&#x8FBE;&#x5F0F;&#xFF0C;&#x662F;&#x4E00;&#x79CD;&#x4EE3;&#x66FF;Java&#x4E2D;&#x7684;&#x533F;&#x540D;&#x5185;&#x90E8;&#x7C7B;&#x7684;&#x65B9;&#x6CD5;&#x3002;
&#x4F7F;&#x7528;object&#x5173;&#x952E;&#x5B57;&#x6765;&#x8FDB;&#x884C;&#x7F16;&#x5199;&#x3002;&#x6BD4;&#x533F;&#x540D;&#x5185;&#x90E8;&#x7C7B;&#x66F4;&#x5148;&#x8FDB;&#x3002;
&#x53EF;&#x4EE5;&#x5B9E;&#x73B0;&#x591A;&#x4E2A;&#x63A5;&#x53E3;&#x3002;</p>
<pre><code class="lang-xml">// &#x5173;&#x952E;  object : &#x6307;&#x660E;
tab_layout.setOnTabSelectListener( object : OnTabSelectListener {
        //  &#x8BBE;&#x7F6E;&#x76D1;&#x542C;&#x51FD;&#x6570;
})
</code></pre>
<h2 id="&#x76D1;&#x542C;&#x51FD;&#x6570;"><a name="&#x76D1;&#x542C;&#x51FD;&#x6570;" class="anchor-navigation-ex-anchor" href="#&#x76D1;&#x542C;&#x51FD;&#x6570;"><i class="fa fa-link" aria-hidden="true"></i></a>1.40. &#x76D1;&#x542C;&#x51FD;&#x6570;</h2>
<pre><code class="lang-text">private val onGestureListener = object : RecordButton.OnGestureListener {
    override fun onUp() {   }
}
</code></pre>
<h2 id="&#x65B0;&#x5EFA;&#x5BF9;&#x8C61;"><a name="&#x65B0;&#x5EFA;&#x5BF9;&#x8C61;" class="anchor-navigation-ex-anchor" href="#&#x65B0;&#x5EFA;&#x5BF9;&#x8C61;"><i class="fa fa-link" aria-hidden="true"></i></a>1.41. &#x65B0;&#x5EFA;&#x5BF9;&#x8C61;</h2>
<p>java&#x4E2D;&#x65B0;&#x5EFA;&#x5BF9;&#x8C61;&#x8981;&#x7528;&#x5230;new &#x5173;&#x952E;&#x5B57;&#x3002; kotlin&#x4E2D;&#x6CA1;&#x6709;new&#x5173;&#x952E;&#x5B57;&#x3002;
&#x76F4;&#x63A5;&#x5199;&#x7C7B;&#x540D; &#x5373;&#x53EF;&#x3002;</p>
<h2 id="get-set-&#x65B9;&#x6CD5;"><a name="get-set-&#x65B9;&#x6CD5;" class="anchor-navigation-ex-anchor" href="#get-set-&#x65B9;&#x6CD5;"><i class="fa fa-link" aria-hidden="true"></i></a>1.42. get set &#x65B9;&#x6CD5;</h2>
<p>kotlin&#x4E2D;&#x53EF;&#x4EE5;&#x76F4;&#x63A5;&#x4F7F;&#x7528;&#x5BF9;&#x8C61;&#x7684;&#x5C5E;&#x6027;&#xFF0C;&#x4E0D;&#x7528;&#x8C03;&#x7528; get&#x548C;set&#x65B9;&#x6CD5;&#x3002;</p>
<pre><code class="lang-xml">//&#x8FD9;&#x662F;FragmentActivity.java&#x4E2D;&#x7684;&#x6E90;&#x7801;
public FragmentManager getSupportFragmentManager() {
    return mFragments.getSupportFragmentManager();
}
&#x4E3A;&#x4E86;&#x83B7;&#x5F97;&#x4E00;&#x4E2A; FragmentManager &#x5B9E;&#x4F8B;&#xFF0C;
java&#x4E2D;&#x9700;&#x8981;&#x8FD9;&#x6837;&#x5199;  this.getSupportFragmentManager() , 
&#x800C;kotlin&#x4E2D;&#x53EF;&#x4EE5;&#x76F4;&#x63A5;&#x8FD9;&#x6837;&#x4F7F;&#x7528; this.supportFragmentManager
&#x6CE8;&#x610F; getSupportFragmentManager &#x548C;getSupportFragmentManager &#x4E4B;&#x95F4;&#x7684;&#x7279;&#x70B9;&#x3002;&#xFF08;&#x7B26;&#x5408;set&#x548C;get&#x7684;&#x547D;&#x540D;&#x89C4;&#x8303;&#x7684;&#xFF09;



//var &#x9ED8;&#x8BA4;&#x6709;get set&#x65B9;&#x6CD5;&#x3002;&#x4E0D;&#x5199;&#x5C31;&#x7528;&#x9ED8;&#x8BA4;&#x7684;&#x3002;
var heiht: Float = 145.4f
        private set  // &#x8BF4;&#x660E;&#x8FD9;&#x4E2A;set&#x65B9;&#x6CD5;&#x662F;&#x79C1;&#x6709;&#x7684;


// &#x91CD;&#x5199;&#x4E86;get&#x65B9;&#x6CD5;
private val isViewAttached: Boolean
    get() = mRootView != null
</code></pre>
<h2 id="&#x5EF6;&#x8FDF;&#x521D;&#x59CB;&#x5316;-&#x3001;-&#x61D2;&#x52A0;&#x8F7D;"><a name="&#x5EF6;&#x8FDF;&#x521D;&#x59CB;&#x5316;-&#x3001;-&#x61D2;&#x52A0;&#x8F7D;" class="anchor-navigation-ex-anchor" href="#&#x5EF6;&#x8FDF;&#x521D;&#x59CB;&#x5316;-&#x3001;-&#x61D2;&#x52A0;&#x8F7D;"><i class="fa fa-link" aria-hidden="true"></i></a>1.43. &#x5EF6;&#x8FDF;&#x521D;&#x59CB;&#x5316; &#x3001; &#x61D2;&#x52A0;&#x8F7D;</h2>
<p> lateinit &#x548C; lazy  &#x3001;notNull</p>
<pre><code class="lang-xml">1&#x3001;lateinit &#x3001;notNull &#x53EA;&#x7528;&#x4E8E;var&#xFF0C;lazy&#x53EA;&#x7528;val

2&#x3001;lateinit &#x4E0D;&#x80FD;&#x7528;&#x5728;&#x53EF;&#x7A7A;&#x7684;&#x5C5E;&#x6027;&#x4E0A;&#x548C; &#x57FA;&#x672C;&#x7C7B;&#x578B;&#x4E0A;&#x3002;
&#x8BA9;&#x7F16;&#x8BD1;&#x671F;&#x5FFD;&#x7565;&#x5BF9;&#x5C5E;&#x6027;&#x672A;&#x521D;&#x59CB;&#x5316;&#x7684;&#x68C0;&#x67E5;&#xFF0C;&#x540E;&#x7EED;&#x5728;&#x54EA;&#x91CC;&#x4EE5;&#x53CA;&#x4F55;&#x65F6;&#x521D;&#x59CB;&#x5316;&#x8FD8;&#x9700;&#x8981;&#x5F00;&#x53D1;&#x8005;&#x81EA;&#x5DF1;&#x51B3;&#x5B9A;&#x3002;
&#xFF08;&#x8BA9;&#x7F16;&#x8BD1;&#x5668;&#x522B;BB&#xFF0C;&#x6211;&#x77E5;&#x9053;&#x8FD9;&#x4E2A;&#x53D8;&#x91CF;&#x4E00;&#x5B9A;&#x8981;&#x521D;&#x59CB;&#x5316;&#xFF0C;&#x522B;&#x8001;&#x662F;&#x63D0;&#x9192;&#x6211;&#xFF09;

3&#x3001;lazy &#x7528;&#x5230;&#x7684;&#x65F6;&#x5019;&#x624D;&#x4F1A;&#x8C03;&#x7528;&#xFF0C;&#x751F;&#x6210;&#x8FC7;&#x7A0B;&#x53EA;&#x4F1A;&#x6267;&#x884C;&#x4E00;&#x6B21;&#xFF0C;
&#x591A;&#x6B21;&#x8C03;&#x7528;&#x7528;&#x5230;&#x7684;&#x662F;&#x7B2C;&#x4E00;&#x6B21;&#x751F;&#x6210;&#x7684;&#x7ED3;&#x679C; &#x3002;

private val linearLayoutManager by lazy {
    LinearLayoutManager(activity, LinearLayoutManager.VERTICAL, false)
}

4&#x3001;&#x4E00;&#x822C;&#x60C5;&#x51B5;&#x4F7F;&#x7528;lateinit&#x4FEE;&#x9970;&#x7B26;&#xFF0C;&#x6700;&#x4E3A;&#x4F18;&#x96C5;&#x3002;
&#x5F53;&#x7C7B;&#x578B;&#x662F;&#x539F;&#x751F;&#x7C7B;&#x578B;&#xFF0C;&#x6216;&#x8005;&#x4E3A;&#x5C40;&#x90E8;&#x53D8;&#x91CF;&#x65F6;&#xFF0C;&#x53EA;&#x80FD;&#x53EA;&#x7528;notNull&#x59D4;&#x6258;&#x3002;
var context: Context by Delegates.notNull()
</code></pre>
<h2 id="&#x7C7B;&#x578B;&#x8F6C;&#x6362;_1"><a name="&#x7C7B;&#x578B;&#x8F6C;&#x6362;_1" class="anchor-navigation-ex-anchor" href="#&#x7C7B;&#x578B;&#x8F6C;&#x6362;_1"><i class="fa fa-link" aria-hidden="true"></i></a>1.44. &#x7C7B;&#x578B;&#x8F6C;&#x6362;</h2>
<pre><code class="lang-xml">&#x5C06;y&#x8F6C;&#x4E3A;String&#x7C7B;&#x578B; &#xFF0C;&#x5982;&#x679C;&#x8F6C;&#x6362;&#x5931;&#x8D25;&#x5C31;&#x4F1A;&#x8FD4;&#x56DE;null &#x3002;
val x: String? = y as? String

// &#x8F6C;&#x6362;&#x5931;&#x8D25;&#x5C31;&#x4F1A;&#x629B;&#x51FA;&#x5F02;&#x5E38;
val x: String? = y as String
</code></pre>
<h2 id="&#x59D4;&#x6258;-by"><a name="&#x59D4;&#x6258;-by" class="anchor-navigation-ex-anchor" href="#&#x59D4;&#x6258;-by"><i class="fa fa-link" aria-hidden="true"></i></a>1.45. &#x59D4;&#x6258; by</h2>
<p>Kotlin &#x76F4;&#x63A5;&#x652F;&#x6301;&#x59D4;&#x6258;&#x6A21;&#x5F0F; &#x3002;  </p>
<pre><code class="lang-xml">&#x59D4;&#x6258;&#x5C5E;&#x6027;&#x4E5F;&#x662F;&#x4E00;&#x79CD; &#x7EA6;&#x5B9A; &#x3002;
setValue &#x548C; getValue&#x90FD;&#x9700;&#x5E26;&#x6709; operator &#x5173;&#x952E;&#x5B57;&#x4FEE;&#x9970;&#x3002;
operator fun getValue(thisRef: Any?, property: KProperty<span class="hljs-tag">&lt;<span class="hljs-name">*</span>&gt;</span>): T {
    return xx
}

operator fun setValue(thisRef: Any?, property: KProperty<span class="hljs-tag">&lt;<span class="hljs-name">*</span>&gt;</span>, value: T) {
    //
}
</code></pre>
<h2 id="&#x661F;&#x53F7;-"><a name="&#x661F;&#x53F7;-" class="anchor-navigation-ex-anchor" href="#&#x661F;&#x53F7;-"><i class="fa fa-link" aria-hidden="true"></i></a>1.46. &#x661F;&#x53F7; *</h2>
<pre><code class="lang-xml">&#x5C06;&#x6570;&#x7EC4;&#x5C55;&#x5F00;&#x5E76;&#x4F20;&#x5165;&#x53EF;&#x53D8;&#x53C2;&#x6570;
val arr = intArrayOf(2, 1, 3)
sumTest( * arr) // &#x661F;&#x53F7;&#x7684;&#x610F;&#x601D;&#x662F;&#x5C06;&#x6570;&#x7EC4;&#x4E2D;&#x7684;&#x503C;&#x53D6;&#x51FA;&#x6765;&#x4F5C;&#x4E3A;&#x53EF;&#x53D8;&#x53C2;&#x6570;

private fun sumTest( vararg values :Int ){
// &#x53C2;&#x6570;&#x662F;&#x53EF;&#x53D8;&#x53C2;&#x6570; 
}
</code></pre>
<h2 id="&#x6CDB;&#x578B;"><a name="&#x6CDB;&#x578B;" class="anchor-navigation-ex-anchor" href="#&#x6CDB;&#x578B;"><i class="fa fa-link" aria-hidden="true"></i></a>1.47. &#x6CDB;&#x578B;</h2>
<p>&#x8DDF;java&#x7684;&#x6CDB;&#x578B;&#x5DEE;&#x4E0D;&#x591A;&#x3002;&#x53C2;&#x8003;java&#x5373;&#x53EF;&#x3002;</p>
<h2 id="kotlin-&#x8C03;&#x7528;jni"><a name="kotlin-&#x8C03;&#x7528;jni" class="anchor-navigation-ex-anchor" href="#kotlin-&#x8C03;&#x7528;jni"><i class="fa fa-link" aria-hidden="true"></i></a>1.48. kotlin &#x8C03;&#x7528;jni</h2>
<p>external&#x8868;&#x793A;&#x5C06;&#x4E00;&#x4E2A;&#x58F0;&#x660E;&#x6807;&#x8BB0;&#x4E3A;&#x4E0D;&#x662F;&#x5728; Kotlin &#x4E2D;&#x5B9E;&#x73B0;.</p>
<pre><code class="lang-xml">init
{
    System.loadLibrary(&quot;joke-lib&quot;)
}

external fun getWXAPPID(): String
</code></pre>
<h2 id="return"><a name="return" class="anchor-navigation-ex-anchor" href="#return"><i class="fa fa-link" aria-hidden="true"></i></a>1.49. return@</h2>
<p>return@XXlabel &#x8BED;&#x6CD5;&#x7528;&#x4E8E;&#x6307;&#x5B9A;&#x6B64;&#x8BED;&#x53E5;&#x4ECE;&#x51E0;&#x4E2A;&#x5D4C;&#x5957;&#x51FD;&#x6570;&#x4E2D;&#x8FD4;&#x56DE;&#x54EA;&#x4E2A;&#x51FD;&#x6570;&#x3002;   </p>
<footer class="page-footer"><span class="copyright">&#x65E0;&#x7248;&#x6743; &#x53EF;&#x4EE5;&#x65E0;&#x9650;&#x5236;&#x4F7F;&#x7528;&#xFF01; all right reserved&#xFF0C;powered by Gitbook</span><span class="footer-modification">&#x8BE5;&#x6587;&#x4EF6;&#x66F4;&#x65B0;&#x65F6;&#x95F4;&#xFF1A;
2020-08-20 17:18:45
</span></footer>
                                
                                </section>
                            
    </div>
    <div class="search-results">
        <div class="has-results">
            
            <h1 class="search-results-title"><span class='search-results-count'></span> results matching "<span class='search-query'></span>"</h1>
            <ul class="search-results-list"></ul>
            
        </div>
        <div class="no-results">
            
            <h1 class="search-results-title">No results matching "<span class='search-query'></span>"</h1>
            
        </div>
    </div>
</div>

                        </div>
                    </div>
                
            </div>

            
                
                <a href="../" class="navigation navigation-prev navigation-unique" aria-label="Previous page: 个人信息">
                    <i class="fa fa-angle-left"></i>
                </a>
                
                
            
        
    </div>

    <script>
        var gitbook = gitbook || [];
        gitbook.push(function() {
            gitbook.page.hasChanged({"page":{"title":"kotlin基础","level":"1.2","depth":1,"previous":{"title":"个人信息","level":"1.1","depth":1,"path":"README.md","ref":"README.md","articles":[]},"dir":"ltr"},"config":{"plugins":["-search","search-plus","todo","anchor-navigation-ex","copy-code-button","fontsettings","tbfed-pagefooter","donate","local-video","splitter","favicon","theme-comscore","local-video"],"styles":{"website":"styles/website.css"},"pluginsConfig":{"tbfed-pagefooter":{"copyright":"无版权 可以无限制使用！","modify_label":"该文件更新时间：","modify_format":"YYYY-MM-DD HH:mm:ss"},"todo":{},"splitter":{},"lunr":{"maxIndexSize":1000000,"ignoreSpecialCharacters":false},"donate":{"alipay":"http://oyru0ayig.bkt.clouddn.com/201803011956_osChina_支付宝收款码.png","alipayText":"支付宝打赏","button":"打赏","title":"","wechat":"http://oyru0ayig.bkt.clouddn.com/201803011956_osChina_微信收款码.png","wechatText":"微信打赏"},"fontsettings":{"family":"sans","size":2,"theme":"sepia"},"highlight":{},"anchor-navigation-ex":{"associatedWithSummary":true,"float":{"floatIcon":"fa fa-navicon","level1Icon":"","level2Icon":"","level3Icon":"","showLevelIcon":false},"mode":"float","multipleH1":true,"pageTop":{"level1Icon":"","level2Icon":"","level3Icon":"","showLevelIcon":false},"printLog":false,"showGoTop":true,"showLevel":true},"favicon":{"shortcut":"assets/images/favicon.ico","bookmark":"assets/images/favicon.ico"},"theme-comscore":{},"local-video":{},"copy-code-button":{},"sharing":{"all":["facebook","google","twitter","weibo","instapaper"],"facebook":true,"google":false,"instapaper":false,"twitter":true,"vk":false,"weibo":false},"theme-default":{"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"showLevel":false},"search-plus":{}},"theme":"default","author":"Aivin","pdf":{"pageNumbers":true,"fontSize":12,"fontFamily":"Arial","paperSize":"a4","chapterMark":"pagebreak","pageBreaksBefore":"/","margin":{"right":62,"left":62,"top":56,"bottom":56}},"structure":{"langs":"LANGS.md","readme":"README.md","glossary":"GLOSSARY.md","summary":"SUMMARY.md"},"variables":{},"title":"Aivin开发笔记","language":"zh-hans","gitbook":"*","description":"Aivin开发笔记"},"file":{"path":"chinese/kotlin基础.md","mtime":"2020-08-20T09:18:45.393Z","type":"markdown"},"gitbook":{"version":"3.2.3","time":"2020-08-20T09:19:23.523Z"},"basePath":"..","book":{"language":""}});
        });
    </script>
</div>

        
    <script src="../gitbook/gitbook.js"></script>
    <script src="../gitbook/theme.js"></script>
    
        
        <script src="../gitbook/gitbook-plugin-search-plus/jquery.mark.min.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-search-plus/search.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-copy-code-button/toggle.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-fontsettings/fontsettings.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-donate/plugin.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-local-video/video.min.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-splitter/splitter.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-lunr/lunr.min.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-lunr/search-lunr.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-sharing/buttons.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-theme-comscore/test.js"></script>
        
    

    </body>
</html>

